package com.tc.juc;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @Auther: tianchao
 * @Date: 2021/9/30 22:07
 * @Description:
 */
@Slf4j
public class SynchronizedTest {

    static final Object lock = new Object();
    static final ReentrantLock REENTRANT_LOCK = new ReentrantLock();

    static int counter = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t2 = new Thread(()->{
            synchronized (lock){
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                   log.info("t2被中断了吗 {}",Thread.currentThread().isInterrupted());
                    e.printStackTrace();
                }
            }
        },"t2");
        t2.start();
        REENTRANT_LOCK.lock();
        Thread t1 = new Thread(()->{
            synchronized (lock){
//                try {
//                    REENTRANT_LOCK.lockInterruptibly();
//                } catch (InterruptedException e) {
//                    log.info("抢占锁的时候被打断了 {}",Thread.currentThread().isInterrupted());
//                    e.printStackTrace();
//                }
                log.info("t2强索");
            }
        },"t1");
        t1.start();
        Thread.sleep(2000);
        log.info("打断t2");
        t1.interrupt();
        log.info("打断t2结束");
        log.info("t1打断标志位： {}",t1.isInterrupted());
    }
}
